﻿using System;
using System.IO;
using System.Xml.Serialization;

namespace Cms.Domain.Authentication
{
    public class Conversion
    {
        public static string ToCompressedString(AuthenticatedUser user)
        {
            var s = new XmlSerializer(typeof(AuthenticatedUser));
            var userStream = new MemoryStream();
            s.Serialize(userStream, user);
            return Convert.ToBase64String(userStream.ToArray());
        }

        public static AuthenticatedUser ToAuthenticatedUser(string compressedString)
        {
            byte[] compressedData = Convert.FromBase64String(compressedString);
            var ms = new MemoryStream(compressedData);
            var s = new XmlSerializer(typeof(AuthenticatedUser));
            return (AuthenticatedUser)s.Deserialize(ms);
        }
    }
}